package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.CookieStore;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.oracle.jrockit.jfr.RequestableEvent;

import dao.FindPasswordDao;
import dao.UserDAO;
import entity.User;

/**
 * Servlet implementation class UserLogin
 */
@WebServlet("/FindPasswordIndex")
public class FindPasswordIndex extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserDAO userDAO = UserDAO.getInstance();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FindPasswordIndex() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("utf-8");
		HttpSession session = (HttpSession)request.getSession(true);
		String user_id = (String)request.getParameter("userid");
		
		FindPasswordDao ps = FindPasswordDao.getInstance();

		
		String result = "";
		int id=Integer.parseInt(user_id);
		if(user_id!="") {
			ps.processCode(id);//产生验证码
			ps.sendCodeEmail(id);//向用户发送验证码
		}
		
		session.setAttribute("find_password_user_id",id);

		response.sendRedirect("FindPassword.jsp");
			
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
